<template>
    <el-form :inline="true" :model="menuForm"  class="demo-form-inline">
      <el-form-item label="菜单名称">
            <el-input v-model="menuForm.menuName" placeholder="请输入名称"></el-input>
        </el-form-item><br/>
        <el-form-item label="父节点">
            <!--<el-select v-model="menuForm.parentId" placeholder="请选择父节点" >-->
                <!--<el-option v-for="father in menu " :label="father.menuName" :value="father.parentId"  :key="father.parentId"></el-option>-->
            <!--</el-select>-->
            <el-select v-model="menuForm.parentId" placeholder="请选择父节点">
                <el-option label="无父结点" value="0"></el-option>
                <el-option
                        v-for="father in menu"
                        :key="father.menuId"
                        :label="father.menuName"
                        :value="father.menuId">
                </el-option>
            </el-select>
        </el-form-item><br/>
        <el-form-item label="地址链接">
            <el-input v-model="menuForm.url" placeholder="请输入名称"></el-input>
        </el-form-item><br/>
       <el-form-item label="图标">
            <el-input v-model="menuForm.icon" placeholder="请输入名称"></el-input>
        </el-form-item><br/>
        是否有效：  <template slot-scope="">
            <el-switch
                    v-model="menuForm.visible"
                    active-color="#13ce66"
                    active-value="0"
                    inactive-value="1"
                    inactive-color="#ff4949"
            >
            </el-switch>
        </template><br/><br/>
        <el-form-item>
            <el-button type="primary"  @click="shuaxin()">刷新</el-button>
            <el-button type="primary" @click="addMenu()">添加</el-button>
        </el-form-item>

    </el-form>

</template>

<script>
    export default {
        name: "menu",
        data(){
            return{
                menuForm:{
                    menuName:"",
                    parentId:"",
                    url:"",
                    visible:"",
                    icon:""
            },
                menu:[],
                text: '',
                textarea: ''
            }

        },
        methods:{
            shuaxin(){
                var that =this;
                that.menuForm={}
            },
            selectParentId(){
                var that =this;
                this.$http.get("system/menu/queryAllFatherId").then(r=>{
                    that.menu= r.data.result.menu

                })

            },
            addMenu(){
                var that =this;
                var username = sessionStorage.getItem("username");
                console.log(that.menuForm)
                this.$http.post(`system/menu/addMenu/${username}`,this.menuForm).then(r=>{
                    var that =this;
                    that.menuForm={};
                    this.$message.success("添加成功")

                })

            },

        },
        mounted(){
            this.selectParentId()
        },
    }
</script>

<style scoped>

</style>